#include<ctype.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
#include<stdlib.h>

// Program to enter the source program.

class oprec
{
   public:
    char label[10];
    char mnemonic[6];
    char operand[10];
   public:
    oprec()
    { strcpy(mnemonic,"");   strcpy(label,"");   strcpy(operand,"");   }

    void indata(int i)
     {
	gotoxy(2,i+4); 	cin>>label;
	gotoxy(15,i+4);	cin>>mnemonic;
	gotoxy(27,i+4);	cin>>operand;
     }

   void outdata(int i)
     {
	gotoxy(2,i+4);	cout<<label;
	gotoxy(15,i+4);	cout<<mnemonic;
	gotoxy(27,i+4);	cout<<operand;
     }

   char* retmnemonic()  	{ return mnemonic;   }
   char* retlabel()	   	{ return label;   }
   char* retoperand()		{ return operand;}

}; // end of class

class outrec:public oprec
{
  char locctr[8];
  char objcode[10];
  public:
  void setlocctr(char x[]) {  strcpy(locctr,x);   }
  void setmnemonic(char x[])  {  strcpy(mnemonic,x); }
  void setlabel(char x[])     {  strcpy(label,x);    }
  void setoperand(char x[])   {  strcpy(operand,x);  }
  void setobjcode(char x[])   {  strcpy(objcode,x);  }

  char * retlocctr()       {  return locctr;      }
  void display(int i)
   {
    gotoxy(2,i+4);	cout<<label;
    gotoxy(15,i+4);	cout<<mnemonic;
    gotoxy(27,i+4);    	cout<<operand;
    gotoxy(40,i+4);	cout<<objcode;
   }
};// end of class

void create()
{
 oprec rec;
 int i=0,j,n,ptr,prev;
 ofstream of;
 ifstream is;

 clrscr();
 cout<<"---------------------------------";
 cout<<"\n LABEL        MNEMONIC    OPERAND";
 cout<<"\n---------------------------------";
 of.open("source.dat",ios::out|ios::binary);
 rec.indata(i);
 while((strcmpi(rec.retlabel(),"/")!=0)||(strcmpi(rec.retmnemonic(),"/")!=0))
 {
  of.write((char*)&rec,sizeof(rec));  i++;
  if(i==20)
	{i=0;   getch();   clrscr();
	 cout<<"---------------------------------";
	 cout<<"\n LABEL        MNEMONIC    OPERAND";
	 cout<<"\n---------------------------------";}
  rec.indata(i);
 }//end of while
 cout<<"\n---------------------------------";
 of.close(); getch();
}

void edit()
{
 oprec rec;
 int i=0,j,n;
 int ptr,prev;
 ofstream of;
 ifstream is;

 clrscr();
 cout<<"---------------------------------";
 cout<<"\n LABEL        MNEMONIC    OPERAND";
 cout<<"\n---------------------------------";
 i=0;
 is.open("source.dat",ios::in|ios::binary);
 while(!is.eof())
 {
  is.read((char*)&rec,sizeof(rec));
  if(!is.eof())
  {
	if(i==20)
	 {i=0;
	  getch();
	  clrscr();
	cout<<"---------------------------------";
	cout<<"\n LABEL        MNEMONIC    OPERAND";
	cout<<"\n---------------------------------";
	  }
	rec.outdata(i);
	i++;
   }
 }//END OF WHILE
 cout<<"\n---------------------------------";
 is.close();

 getch();
}
